{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# python目录和文件IO\n",
    "\n",
    "    os.walk(top):遍历top目录\n",
    "    os.listdir(dirname):列出dirname下的目录和文件\n",
    "    os.getcwd():获得当前工作目录\n",
    "    os.curdir:返回但前目录（'.')\n",
    "    os.chdir(dirname):改变工作目录到dirname\n",
    "    os.path.isdir(name):判断name是不是一个目录，name不是目录就返回false\n",
    "    os.path.isfile(name):判断name是不是一个文件，不存在name也返回false\n",
    "    os.path.exists(name):判断是否存在文件或目录name\n",
    "    os.path.getsize(name):获得文件大小，如果name是目录返回0L\n",
    "    os.path.abspath(name):获得绝对路径\n",
    "    os.path.normpath(path):规范path字符串形式\n",
    "    os.path.split(name):分割文件名与目录\n",
    "    os.path.splitext():分离文件名与扩展名\n",
    "    os.path.join(path,name):连接目录与文件名或目录\n",
    "    os.path.basename(path):返回文件名\n",
    "    os.path.dirname(path):返回文件路径"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "python元编程.ipynb\n",
      "python函数式编程.ipynb\n",
      "python命名空间.ipynb\n",
      "python字符串和格式化.ipynb\n",
      "python描述器.ipynb\n",
      "python时间和日期.ipynb\n",
      "python正则re.ipynb\n",
      "python生成器.ipynb\n",
      "python目录和文件IO.ipynb\n",
      "python经典类和新类.ipynb\n",
      "python装饰器.ipynb\n",
      "python迭代器.ipynb\n",
      "python错误和异常.ipynb\n",
      "python面向对象和魔法函数.ipynb\n",
      "有关Python.ipynb\n",
      "python函数式编程-checkpoint.ipynb\n",
      "python命名空间-checkpoint.ipynb\n",
      "python字符串和格式化-checkpoint.ipynb\n",
      "python描述器-checkpoint.ipynb\n",
      "python正则re-checkpoint.ipynb\n",
      "python生成器-checkpoint.ipynb\n",
      "python目录和文件IO-checkpoint.ipynb\n",
      "python装饰器-checkpoint.ipynb\n",
      "python迭代器-checkpoint.ipynb\n",
      "有关Python-checkpoint.ipynb\n",
      ".ipynb_checkpoints\n",
      "python元编程.ipynb\n",
      "python函数式编程.ipynb\n",
      "python命名空间.ipynb\n",
      "python字符串和格式化.ipynb\n",
      "python描述器.ipynb\n",
      "python时间和日期.ipynb\n",
      "python正则re.ipynb\n",
      "python生成器.ipynb\n",
      "python目录和文件IO.ipynb\n",
      "python经典类和新类.ipynb\n",
      "python装饰器.ipynb\n",
      "python迭代器.ipynb\n",
      "python错误和异常.ipynb\n",
      "python面向对象和魔法函数.ipynb\n",
      "有关Python.ipynb\n",
      "D:\\src\\about-python\\python语法\n"
     ]
    }
   ],
   "source": [
    "# -*- coding:utf-8 -*-\n",
    "import os\n",
    "for root, dirs, files in os.walk('.'):\n",
    "    for file in files:\n",
    "        print file.decode('gbk')\n",
    "    \n",
    "for i in os.listdir('.'):\n",
    "    print i.decode('gbk')\n",
    "    \n",
    "print os.getcwd().decode('gbk')\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
